// pages/fat/detail/index.wxml.js
const app = getApp()  
const bodyFatData = require('../bodyFatData.js')
Page({
  id: null,
  /**
   * 页面的初始数据
   */
  data: {
    bodyFatDataArray: bodyFatData.getAllBodyFatDataArray()
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.id = options.id
    bodyFatData.setUserInfo(app.globalData.user)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getWeightRecord()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },
  getWeightRecord: function () {
    wx.request({
      url: app.globalData.api_domain + 'min-pro/weight-record/'+ this.id,
      method: 'GET',
      header: {
        'token': app.globalData.user.token // 默认值
      },
      success: (res) => {
        console.log("getWeightRecord", res);
        if (res.statusCode == 200) {
          if (res.data.apistatus == 1) {
            bodyFatData.bodyFatData.weight = res.data.result.weight
            bodyFatData.bodyFatData.bmi = res.data.result.bmi
            bodyFatData.bodyFatData.fat_rate = res.data.result.fat_rate
            bodyFatData.bodyFatData.muscle_rate = res.data.result.muscle_rate
            bodyFatData.bodyFatData.water_content = res.data.result.water_content
            bodyFatData.bodyFatData.bone_mass = res.data.result.bone_mass
            bodyFatData.bodyFatData.basal_metabolism = res.data.result.basal_metabolism
            bodyFatData.bodyFatData.visceral_fat = res.data.result.visceral_fat
            bodyFatData.bodyFatData.subcutaneous_fat = res.data.result.subcutaneous_fat
            bodyFatData.bodyFatData.protein_rate = res.data.result.protein_rate
            bodyFatData.bodyFatData.standard_weight = res.data.result.standard_weight
            bodyFatData.bodyFatData.weight_control = res.data.result.weight_control
            bodyFatData.bodyFatData.except_fat_weight = res.data.result.except_fat_weight
            bodyFatData.bodyFatData.muscle_volume = res.data.result.muscle_volume
            bodyFatData.bodyFatData.fat_volume = res.data.result.fat_volume
            bodyFatData.bodyFatData.body_age = res.data.result.body_age
            bodyFatData.bodyFatData.protein_content = res.data.result.protein_content
            bodyFatData.setBmi(bodyFatData.bodyFatData.bmi)
            bodyFatData.setFatRate(bodyFatData.bodyFatData.fat_rate)
            bodyFatData.setVisceralFat(bodyFatData.bodyFatData.visceral_fat)
            bodyFatData.setMuscleRate(bodyFatData.bodyFatData.muscle_rate)
            bodyFatData.setBasalMetabolism(bodyFatData.bodyFatData.basal_metabolism)
            bodyFatData.setBoneMass(bodyFatData.bodyFatData.bone_mass)
            bodyFatData.setWaterContent(bodyFatData.bodyFatData.water_content)
            bodyFatData.setProteinRate(bodyFatData.bodyFatData.protein_rate)
            console.log(bodyFatData.bodyFatData)
            console.log(bodyFatData.getBodyFatDataArray())
            
            this.setData({ bodyFatDataArray: bodyFatData.getAllBodyFatDataArray()})
          }
        }
      }
    })
  },
})